#include("/common/include/include.html")
<style>
    .lay-body{
        margin-top: 52px;
        overflow-y: auto;
        overflow-x: unset;
    }
    .lay-header{
        position: absolute;
        top: 0px;
        width: 100%;
    }
</style>
<div class="modal-dialog" style="width:100%">
    <div class="modal-content">
        <div class="modal-header lay-header">
            <button type="button" class="close" data-dismiss="modal" onclick="{parent.layer.closeAll();}"><i class="pci-cross pci-circle"></i></button>
            <h4 class="modal-title">选择父级指标</h4>
        </div>

        <div class="modal-body lay-body">
            <ul id="treeDemo" class="ztree"></ul>
        </div>
    </div>
</div>

<script>
    var paperid = parent.$("#id").val();
    //树
    var setting = {
        check: {
            enable: true,
            chkStyle: "checkbox",
            chkboxType: { "Y": "s", "N": "s" }
        },
        async : {
            enable : true,
            url : ctx + "/admin/paperbase/getAllTree"
        },
        callback : {
            onCheck  : checkNode,
            onAsyncSuccess: function(){//默认勾选已有
                var zTree = $.fn.zTree.getZTreeObj("treeDemo");
                //var data = common_ajax.ajaxFunc("/admin/paper/getDataByPaperid", {"paperid":paperid}, "json", null);

                /*if(data&&data.length>0){
                    $.each(data,function(i,d){
                        var node = zTree.getNodeByParam("id", d.base_id, null);//根据menuid获取节点
                        if(node){
                            zTree.checkNode(node, true, false, true);//将节点选中
                        }
                    })
                }*/
                var pid = parent.$("#pId").val().split(",")
                if(pid&&pid.length>0){
                    for(var i = 0;i<pid.length;i++){
                        var node = zTree.getNodeByParam("id", pid[i], null);//根据menuid获取节点
                        if(node){
                            zTree.checkNode(node, true, false, true);//将节点选中
                        }
                    }
                }
            }
        }
    };
    /***
     * 选择树
     **/
    function checkNode(event, treeId, treeNode) {
        var treeObj = $.fn.zTree.getZTreeObj("treeDemo");
        var node = treeObj.getCheckedNodes(true);
        parent.pointLion.setManyItemNode(node);
    }

    $(document).ready(function() {
        $.fn.zTree.init($("#treeDemo"), setting);//初始化树
        var clientH = document.body.clientHeight-54;
        $(".lay-body").css("height",clientH+"px");
    });
</script>
